const child_process = require("child_process");
const path = require("path");
module.exports = {
    runElectron,
    runElectronBuild
};
const rootPath = path.resolve(__dirname, "../");

/**
 * 开发环境下运行 electron
 */
function runElectron() {
    const  exec = child_process.exec;

    exec("electron .", {cw:rootPath}, function (err, st, ste) {
        if(err){
            console.error(err);
        }
        // 中断进程
        process.exit(0)
    });
    process.on("exit", function () {
        console.log("应用退出");
    });
}

/**
 * webpack 打包执行完毕之后 开始打包客户端
 */
function runElectronBuild() {
    console.log("代码打包完成..")
    console.log("开始生成客服端....");
    const  exec = child_process.exec;
    exec("electron-builder build --win", {cw:rootPath}, function (err, st, ste) {
        if(err){
            console.error(err);
        }
        // 中断进程
        process.exit(0)
    });
    process.on("exit", function () {
        console.log("客户端生成完毕");
    });
}

